/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.web30.bookmark.webservice.config;

import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.jersey.api.json.JSONJAXBContext;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ext.ContextResolver;
import javax.xml.bind.JAXBContext;
import org.web30.bookmark.Bookmark;
import org.web30.bookmark.Bookmarks;

/**
 *
 * @author xiazy
 */
public class JAXBContextResolver implements ContextResolver<JAXBContext>{
    private final JAXBContext context;

    private final Set<Class> types;

    private final Class[] cTypes = {Bookmarks.class, Bookmark.class};

    public JAXBContextResolver() throws Exception {
        this.types = new HashSet(Arrays.asList(cTypes));
        this.context = new JSONJAXBContext(JSONConfiguration.natural().build(), cTypes);
    }

    public JAXBContext getContext(Class<?> objectType) {
        return (types.contains(objectType)) ? context : null;
    }
}
